package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    //保存申请表单
    @PostMapping("/save")
    public JsonResult saveApplication(ApplicationSaveParam saveParam){
        log.debug("保存车辆申请表单的对象是：{}",saveParam);
        applicationService.save(saveParam);
        return JsonResult.ok();
    }
    //查询申请表单
    @GetMapping("/select")
    public JsonResult selectApplication(ApplicationQuery applicationQuery){
      List<ApplicationVO> applicationVOList = applicationService.selectApplication(applicationQuery);
      return JsonResult.ok(applicationVOList);
    }
    //撤销申请单
    @PostMapping("/cancel/{id}")
    public JsonResult cancelApplication(@PathVariable Long id){
        applicationService.cancel(id);
        return JsonResult.ok();
    }
    //分配车辆
    @PostMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }
    //还车
    @PostMapping("/back/{applicationId}/{vehicleId}")
    public JsonResult back(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        applicationService.back(applicationId,vehicleId);
        return JsonResult.ok();
    }
}
